function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

function addcookie(name, value, expireHours) {
    var cookieString = name + "=" + escape(value) + "; path=/";
    //判断是否设置过期时间
    if (expireHours > 0) {
        var date = new Date();
        date.setTime(date.getTime + expireHours * 3600 * 1000);
        cookieString = cookieString + "; expire=" + date.toGMTString();
    }
    document.cookie = cookieString;
}

function getcookie(name) {
    var strcookie = document.cookie;
    var arrcookie = strcookie.split("; ");
    for (var i = 0; i < arrcookie.length; i++) {
        var arr = arrcookie[i].split("=");
        if (arr[0] == name)return arr[1];
    }
    return "";
}

function delCookie(name) {//删除cookie
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getcookie(name);
    if (cval != null) document.cookie = name + "=" + cval + "; path=/;expires=" + exp.toGMTString();
}

function checklogin(state) {
    if (state == 0) {
        location.href = WapSiteUrl + '/tmpl/member/login.html';
        return false;
    } else {
        return true;
    }
}

function contains(arr, str) {
    var i = arr.length;
    while (i--) {
        if (arr[i] === str) {
            return true;
        }
    }
    return false;
}

function buildUrl(type, data) {
    switch (type) {
        case 'keyword':
            return WapSiteUrl + '/tmpl/product_list.html?keyword=' + encodeURIComponent(data);
        case 'special':
            return WapSiteUrl + '/special.html?special_id=' + data;
        case 'goods':
            return WapSiteUrl + '/tmpl/product_detail.html?goods_id=' + data;
        case 'url':
            return data;
    }
    return WapSiteUrl;
}
//bottom nav ww w.s h o pj l.com 出 品
$(function () {
    setTimeout(function () {
        if ($("#content .container").height() < $(window).height()) {
            $("#content .container").css("min-height", $(window).height());
        }
    }, 300);
    $("#bottom .nav .get_down").click(function () {
        $("#bottom .nav").animate({"bottom": "-50px"});
        $("#nav-tab").animate({"bottom": "0px"});
    });
    $("#nav-tab-btn").click(function () {
        $("#bottom .nav").animate({"bottom": "0px"});
        $("#nav-tab").animate({"bottom": "-40px"});

    });
    setTimeout(function () {
        $("#bottom .nav .get_down").click();
    }, 500);
    $("#scrollUp").click(function (t) {
        $("html, body").scrollTop(300);
        $("html, body").animate({
            scrollTop: 0
        }, 300);
        t.preventDefault()
    });
});


var layermsg = function (msg, callback) {
    layer.open({
        style: 'border:none; background-color:rgba(0,0,0,.75); color:#fff;',
        content: '<div style="text-align:center;">' + msg + '</div>',
        time: 2
    });

    if (callback) {
        setTimeout(function () {
            callback.call();
        }, 2000);
    }
}


//DOM事件加载完毕后，创建微信登录
document.addEventListener("DOMContentLoaded", function () {
    do {
        var href = location.href.replace(location.origin, "");
        var member_id = getcookie('member_id');
        if (href.indexOf('uid=') > -1) {
            //如果是通过别人的链接进来的
            var mid = href.match(/uid=([\d]+)/)[1];
            if (mid != member_id) {
                addcookie("from_member", mid);
            }
            break;
        }

        // TODO::
        //if (member_id != null && member_id != '') {
        //
        //    if (href.indexOf('?') == -1) {
        //        href += '?uid=' + member_id;
        //    }
        //    else {
        //        href += '&uid=' + member_id;
        //    }
        //    history.pushState("", "", href);
        //
        //
        //    $('i.back,.fa-chevron-left').closest('a').attr('href', 'javascript:history.go(-2)');
        //
        //}

    } while (0);

    ////LOGIN页面不生效
    //if ((/login\.php/).test(location.href)) {
    //    return;
    //}
    //var ua = window.navigator.userAgent.toLowerCase();
    //
    //if (ua.match(/MicroMessenger/i) != 'micromessenger') {
    //    return;
    //}
    //
    //var key = getcookie("key");
    //if (key == null || key == '') {
    //    location.href = '/wap/jssdk/wechat_login.php?ref=' + encodeURIComponent(window.location.href);
    //}


});